<template>
    <div class="body-bj" ref="homePage">
        <div class="header"></div>
		<div class="centent">
			<span class="biaoti">GPC项目控制专业人士资格认证报名系统</span>
			<div class="login-box">
                <div class="login-ww">
                    <div class="login-input">
                        <div class="login-zh">
                            <el-tabs v-model="activeName" @tab-click="handleClick">
                                <el-tab-pane label="学员登录" name="first">
                                    <input type="text" name="" id="" v-model="studentsForm.username" value="" placeholder="手机号/邮箱/用户名" />
                                    <input type="password" name="" id="" v-model="studentsForm.password" value="" placeholder="请输入密码" />
                                    <div class="checkbox-el">
                                        <el-checkbox v-model="checked">记住登录名</el-checkbox>
                                        <router-link tag="span" :to="{name:'password',query:{source:'考生'}}">忘记密码</router-link>
                                    </div>
                                    <span class="login-button" @click="studentsLogin()">登陆</span>
                                </el-tab-pane>
                                <el-tab-pane label="机构登录" name="second">
                                    <input type="text" name="" id="" v-model="studentsForm1.username" value="" placeholder="手机号/邮箱/用户名" />
                                    <input type="password" name="" v-model="studentsForm1.password" id="" value="" placeholder="请输入密码" />
                                    <div class="checkbox-el">
                                        <el-checkbox v-model="checked">记住登录名</el-checkbox>
                                        <router-link tag="span" :to="{name:'password',query:{source:'机构'}}">忘记密码</router-link>
                                        <router-link tag="span" :to="{name:'registered'}">注册机构</router-link>
                                    </div>
                                    <span class="login-button" @click="institutionsLogin()">登陆</span>
                                </el-tab-pane>
                            </el-tabs>
                        </div>
                    </div>
                </div>
			</div>
		</div>
        <ul class="falv clearfix">
            <router-link tag="li" :to="{path:'theLaw',query:{name:'法律声明'}}"><span>法律声明</span></router-link>
            <router-link tag="li" :to="{path:'theLaw',query:{name:'隐私政策声明'}}"><span>隐私政策声明</span></router-link>
            <router-link tag="li" :to="{path:'theLaw',query:{name:'举报不良信息'}}"><span>举报不良信息</span></router-link>
            <router-link tag="li" :to="{path:'theLaw',query:{name:'可接受的使用政策'}}"><span>可接受的使用政策</span></router-link>
        </ul>
    </div>
</template>
<script>
import apiHttp from '../api/index.js'
export default {
    data(){
        return{
            clientHeight:'',
            activeName: 'first',
            checked:localStorage.getItem('isKeep') ? true : false,
            studentsForm:{
                username:localStorage.getItem('xyName') ? localStorage.getItem('xyName') : '',
                subType:0,          //子类型 0考生 1机构
                type:3,             //用户类型 1手机 2电子邮箱 3用户名 4微信
            },
            studentsForm1:{
                username:localStorage.getItem('jgName') ? localStorage.getItem('jgName') : '',
                subType:1,          //子类型 0考生 1机构
                type:3,             //用户类型 1手机 2电子邮箱 3用户名 4微信
            }
        }
    },
    mounted(){
        this.clientHeight = `${document.documentElement.clientHeight}`
        window.onresize = function temp(){
            this.clientHeight = `${document.documentElement.clientHeight}`
        }
    },
    watch:{
        clientHeight(){
            this.changeFixed(this.clientHeight)
        },
        // 监听是否点击记住账号
        checked(newVal,oldVal){
            if(newVal){
                localStorage.setItem('isKeep',true)
                localStorage.setItem('xyName',this.studentsForm.username)
                localStorage.setItem('jgName',this.studentsForm1.username)
            }else{
                localStorage.removeItem('isKeep')
                localStorage.removeItem('xyName')
                localStorage.removeItem('jgName')
            }
        },
        // 监听name名字
        studentsForm:{
            deep: true,
            handler(newVal,oldVal){
                if(this.checked){
                    localStorage.setItem('xyName',newVal.username)
                }else{
                    localStorage.removeItem('xyName')
                }
            }
        },
        // 监听name名字
        studentsForm1:{
            deep: true,
            handler(newVal,oldVal){
                if(this.checked){
                    localStorage.setItem('jgName',newVal.username)
                }else{
                    localStorage.removeItem('jgName')
                }
            }
        }
    },
    methods:{
        changeFixed(clientHeight){
            let w = clientHeight
            this.$refs.homePage.style.height = `${w}px`
        },
        handleClick(tab, event) {
            // if(tab.name == 'first'){
            //     this.studentsForm.subType = 0

            // }else{
            //     this.studentsForm.subType = 1
            // }
        },
        // 考生登录
        studentsLogin(){
            apiHttp.apiIndex.login(this.studentsForm).then(resp =>{
                if(resp.code == 0){
                    localStorage.setItem('adminTokens',resp.data)
                    sessionStorage.setItem('infoImg',1)
                    this.$router.push({
                        path:'/students/index',
                    })
                }else{
                    this.$message.error(resp.message)
                }
            })
        },
        // 机构登陆
        institutionsLogin(){
            apiHttp.apiIndex.login(this.studentsForm1).then(resp =>{
                if(resp.code == 0){
                    localStorage.setItem('adminTokens',resp.data)
                    sessionStorage.setItem('infoImg',2)
                    this.$router.push({
                        path:'/institutions/index',
                    })
                }else{
                    this.$message.error(resp.message)
                }
            })
        }
    }
}
</script>

<style scoped>
.body-bj{
    width: 100%;
    height: 100%;
    background: url(../../static/img/content.jpg) no-repeat center;
    background-size: cover;
    overflow: hidden;
    position: relative;
}
.header{
    background: url(../../static/img/header.jpg) no-repeat center #5d2805;
    width: 100%;
    height: 119px;
}
.centent{
    width: 100%;
    height: 100%;
}
.login-box{
    width: 365px;
    height: 365px;
    position: fixed;
    top:50%;
    left: 50%;
    margin-left: -182px;
    margin-top: -142px;
    background: url(../../static/img/kuang.png) no-repeat center;
}
.login-ww{
    margin:10px;
    width: 345px;
    height: 345px;
    background-color: #f7f5ec;
    overflow: hidden;
}
.login-input{
    width: 290px;
    height: 290px;
    background-color: #fff;
    margin: 27px auto;
    box-shadow: 0 0 10px #e2dacd;
}
.login-zh{
    width: 250px;
    height: 250px;
    padding: 20px;
}
.login-input input{
    height: 38px;
    border: solid 1px #bfbfbf;
    width: 90%;
    font-size: 14px;
    color: #000;
    line-height: 38px;
    outline:none;
    padding-left: 5%;
    margin-top: 10px;
    border-radius: 3px;
}
.checkbox-el{
    height: 20px;
    width: 94%;
    margin: 10px auto 0;
}
.checkbox-el span{
    font-size: 12px;
    float: right;
    cursor: pointer;
}
.checkbox-el span:nth-child(2){
    padding-left: 10px;
}
.login-button{
    background-color: #5d2805;
    height: 40px;
    width: 100%;
    margin-top: 20px;
    line-height: 40px;
    color: #fff;
    font-size: 16px;
    display: block;
    text-align: center;
    border-radius: 5px;
}
.biaoti{
    width: 100%;
    font-size: 34px;
    font-weight: bold;
    text-align: center;
    padding-top: 30px;
    display: block;
}
</style>
